﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using BemEstarEmprego.Web.Models;
using BemEstarEmprego.BLL;
using BemEstarEmprego.BLL.Models;
using BemEstarEmprego.Entities;
using BemEstarEmprego.Web.Helpers;

namespace BemEstarEmprego.Web.Controllers
{

	public class AdmController : BaseController
	{

		public ActionResult LogOn(LogOnModel model)
		{
			usuario user;
			UserBLL userLogin;
			LogOnModel _Model = new LogOnModel();

			try
			{
				if (model.usuario != null)
				{
					user = new usuario();
					user.LOGIN = model.usuario.User;
					user.SENHA = model.usuario.Password;
					userLogin = new UserBLL();


					if (!String.IsNullOrWhiteSpace(model.usuario.User) || !String.IsNullOrWhiteSpace(model.usuario.User))
					{
						if (userLogin.Login(user))
						{
							return View("AdmIndex");
						}
						else
						{
							_Model.usuario = new UsuarioApp() { Password = "", User = "", IsValidUser = false};
							ViewBag.MsgErro = "Usuário / Senha inválido(a). Contate o Administrador.";
							return View("LogOn", _Model);
						}
					}
					else
					{
						_Model.usuario = new UsuarioApp() { Password = "", User = "", IsValidUser = false};
						ViewBag.MsgErro = "Informar Usuário ou Senha.";
						return View("LogOn", _Model);
					}
				}
			}
			catch (Exception ex)
			{
				throw new Exception(String.Format("Erro:{0}" + Environment.NewLine + " Menssangem Interna:{1}",
									ex.Message,
									ex.InnerException.Message));
			}
			return View();
		}

		public ActionResult LogOff()
		{
			HttpContext.Session["UsuarioSession"] = null;
			return RedirectToAction("Home");
		}

		[SecurityFilter]
		public ActionResult Index()
		{
			return View("AdmIndex");
		}
	}
}